package dao;

import pojo.Btcfrelation;
import util.DbUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class BtcfrelationDao {
    private Connection conn = null;
    private PreparedStatement pstm = null;
    private ResultSet rs = null;
    //    获取tbid对应的类型
    public List<Btcfrelation> getBtcfrelationList(int tbid){
        List<Btcfrelation> btcflist = new ArrayList<>();
        try{
            conn = DbUtil.getConnection();
            String sql = "select * from btcfrelation where tbid="+tbid;
            pstm = conn.prepareStatement(sql);
            rs = pstm.executeQuery(sql);
            while (rs.next()){
                Btcfrelation btcfrelation = new Btcfrelation();
                btcfrelation.setId(Integer.parseInt(rs.getString("id")));
                btcfrelation.setCftype(rs.getString("cftype"));
                btcfrelation.setTbid(Integer.parseInt(rs.getString("tbid")));
                btcflist.add(btcfrelation);
            }
        }catch (SQLException e){
            e.printStackTrace();
        }finally{
            DbUtil.close(conn, pstm, rs);
        }
        return btcflist;


    }
}
